package com.mall.coupon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mall.common.page.PageData;
import com.mall.common.service.impl.CrudServiceImpl;
import com.mall.common.utils.ConvertUtils;
import com.mall.coupon.dao.SeckillSkuRelationDao;
import com.mall.coupon.dto.SeckillSkuRelationDTO;
import com.mall.coupon.entity.SeckillSkuRelationEntity;
import com.mall.coupon.service.SeckillSkuRelationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 秒杀活动商品关联
 *
 * @author xjc xjc@163.com
 * @since 1.0.0 2022-07-17
 */
@Service
public class SeckillSkuRelationServiceImpl extends CrudServiceImpl<SeckillSkuRelationDao, SeckillSkuRelationEntity, SeckillSkuRelationDTO> implements SeckillSkuRelationService {

    @Override
    public QueryWrapper<SeckillSkuRelationEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<SeckillSkuRelationEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


    @Override
    public PageData<SeckillSkuRelationDTO> listProductByParam(Map<String, Object> params) {
        QueryWrapper<SeckillSkuRelationEntity> queryWrapper = new QueryWrapper<>();
        if (params.containsKey("promotionSessionId"))
            queryWrapper.eq("promotion_session_id",params.get("promotionSessionId"));
        List<SeckillSkuRelationEntity> selectList = baseDao.selectList(queryWrapper);
        return new PageData<>(ConvertUtils.sourceToTarget(selectList,SeckillSkuRelationDTO.class),selectList.size());
    }

    @Override
    public List<SeckillSkuRelationEntity> listByWapper(QueryWrapper<SeckillSkuRelationEntity> wrapper) {
        return baseDao.selectList(wrapper);
    }
}